package Basic

object ArrayTest {
  def main(args: Array[String]): Unit = {

    val intValueArr = new Array[Int](3) //声明一个长度为3的整型数组，每个数组元素初始化为0
    intValueArr(0) = 12 //给第1个数组元素赋值为12
    intValueArr(1) = 45 //给第2个数组元素赋值为45
    intValueArr(2) = 33 //给第3个数组元素赋值为33

    val myStrArr = new Array[String](3) //声明一个长度为3的字符串数组，每个数组元素初始化为null
    myStrArr(0) = "BigData"
    myStrArr(1) = "Hadoop"
    myStrArr(2) = "Spark"
    //    for (i <- 0 to 2) println(myStrArr(i))

    //多维数组的创建
    val myMatrix = Array.ofDim[Int](3, 4) //类型实际就是Array[Array[Int]]
    val myCube = Array.ofDim[String](3, 2, 4) //类型实际是Array[Array[Array[Int]]]
    //访问第一行第二列的元素
    println(myMatrix(0)(1))
  }
}
